#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include "Platform.h"

#ifndef _ARP_SCANNER_H_
#define _ARP_SCANNER_H_

#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")



struct ArpHostInfo{
	ArpHostInfo(ULONG _ipAddr = 0, ULONG *_macAddr = NULL, DWORD _physAddrLen = 0) {
		ipAddress = _ipAddr;
		physAddrLen = _physAddrLen;
		if (_macAddr != NULL)
			memcpy(macAddress, _macAddr, sizeof(macAddress));
	}
	DWORD physAddrLen{ 0 };
	ULONG ipAddress{0};
	ULONG macAddress[2]{0,0};

	void PrintInfo() {

		BYTE ip[4]{ 0 };
	//	printf("%u\n", ipAddress);
		auto delta = ipAddress;
		for (auto i = 0; i < 4; i++) {
			ip[i] = delta &((1 << 8) - 1);
			delta >>= 8;
			if (i != 3)
				printf("%d.", ip[i]);
			else
				printf("%d\tMac:", ip[i]);
		}

		auto bPhysAddr = (BYTE *)& macAddress;
		
		if (physAddrLen) {
			for (int i = 0; i < (int)physAddrLen; i++) {
				if (i == (physAddrLen - 1))
					printf("%.2X\n", (int)bPhysAddr[i]);
				else
					printf("%.2X-", (int)bPhysAddr[i]);
			}
		}
		else
			printf
			("Warning: SendArp completed successfully, but returned length=0\n");
	}
};

class ArpScanner {
public:
	ResultCode ScanTargetIP(TCHAR *ipAddress, ArpHostInfo &dstHost);
	ResultCode ScanSubnet(TCHAR *Subnet_Adresss);
	DWORD ScanByInt(IPAddr destIP, ArpHostInfo &destHost);
private:
	std::vector<ArpHostInfo> m_aliveHost;
	//DWORD ScanByInt(IPAddr destIP, ArpHostInfo &destHost);
};

#endif;